package model

import (
	"gorm.io/gorm"
	"time"
	"wechat-moments_0926/config"
)

type Comment struct {
	Id        uint32         `gorm:"column:id;type:int UNSIGNED;comment:id;primaryKey;not null;" json:"id"`                                    // id
	FeedId    int32          `gorm:"column:feed_id;type:int;comment:动态ID;not null;" json:"feed_id"`                                            // 动态ID
	UserId    int32          `gorm:"column:user_id;type:int;comment:用户ID;not null;" json:"user_id"`                                            // 用户ID
	Content   string         `gorm:"column:content;type:varchar(300);comment:评论内容;not null;" json:"content"`                                   // 评论内容
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);comment:评论时间;not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"` // 评论时间
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (c *Comment) TableName() string {
	return "comment"
}

func (c *Comment) AddComment() error {
	return config.DB.Create(&c).Error
}
